# app/__init__.py

from flask import Flask, json
from flask_cors import CORS

import sys
import os
from minio import Minio
from minio.error import S3Error

# 将项目根目录添加到 sys.path
sys.path.append(os.path.dirname(os.path.abspath(__file__)))

app = Flask(__name__)
app.config.from_object('config.Config')  # 修改这里
CORS(app, resources={
    r"/*": {
        "origins": "*",
        "methods": ["GET", "POST", "PUT", "DELETE", "OPTIONS"],
        "allow_headers": "*",
        "supports_credentials": True
    }
})

# 初始化 MinIO 客户端
app.minio = Minio(
    endpoint = "117.72.37.61:9000",  # MinIO 服务器地址
    access_key="minio@123",  # 访问密钥
    secret_key="minio@123",  # 秘密密钥
    secure=False  # 是否使用 HTTPS
)

from app.controllers.user_controller import user
from app.controllers.comment_insert_controller import insert_comment
from app.controllers.comment_select_controller import select_comment
from app.controllers.note_controller import note
from app.controllers.shop_controller import shop
from app.controllers.oss_cotroller import oss
from app.controllers.follow_controller import follow
from app.controllers.recomment_controller import recommend
from app.controllers.search_category_controller import search_category
from app.controllers.map_controller import map
from app.controllers.comment_controller import comment

app.register_blueprint(user, url_prefix='/user')
app.register_blueprint(note, url_prefix='/note')
app.register_blueprint(insert_comment, url_prefix='/insert_comment')
app.register_blueprint(select_comment, url_prefix='/select_comment')
app.register_blueprint(shop, url_prefix='/shop')
app.register_blueprint(oss, url_prefix='/oss')
app.register_blueprint(follow, url_prefix='/follow')
app.register_blueprint(recommend, url_prefix='/recommend')
app.register_blueprint(search_category, url_prefix='/search_category')
app.register_blueprint(map, url_prefix='/map')
app.register_blueprint(comment, url_prefix='/comment')

from flask import Blueprint,request,Flask
@app.before_request
def log_request():
    print("Incoming request:", request.headers)
    print("Request method:", request.method)
    # print("Request body:", request.get_data())